package city.spring.modules.material.service.impl;

import city.spring.modules.material.entity.MaterialSettingEntity;
import city.spring.modules.material.repository.MaterialSettingRepository;
import city.spring.modules.material.service.MaterialSettingService;
import city.spring.modules.material.vo.MaterialVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class MaterialSettingServiceImpl extends ServiceImpl<MaterialSettingRepository, MaterialSettingEntity> implements MaterialSettingService {

    private final MaterialSettingRepository materialSettingRepository;

    public MaterialSettingServiceImpl(MaterialSettingRepository materialSettingRepository) {

        this.materialSettingRepository = materialSettingRepository;
    }

    @Override
    public MaterialSettingEntity getById(String id) {
        return materialSettingRepository.getById(id);
    }


    @Override
    public IPage<MaterialVO> listPage(Page<? extends MaterialSettingEntity> page, Wrapper<? extends MaterialSettingEntity> wrapper) {
        return baseMapper.listPage(page, wrapper);
    }

    @Override
    public IPage<MaterialVO> getMaterialPage(Page<? extends MaterialSettingEntity> page, Wrapper<? extends MaterialSettingEntity> wrapper) {
        return baseMapper.getMaterialPage(page, wrapper);
    }

    @Override
    public void updateMaterial(MaterialSettingEntity entity) {
        boolean update = updateById(entity);

        if (!update) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public IPage<MaterialVO> MaterialByCategoryIdlistPage(Page<? extends MaterialSettingEntity> page, Wrapper<? extends MaterialSettingEntity> wrapper, String categoryId) {
        return baseMapper.MaterialByCategoryIdlistPage(page, wrapper, categoryId);
    }
}
